<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>运营工具</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/tool.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/mobiscroll.core-2.5.2.css"  />
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/mobiscroll.android-ics-2.5.2.css"  />
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.core-2.5.2.js"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.datetime-2.5.1.js"></script>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/mobiscroll.android-ics-2.5.2.js"></script>
</head>
<body>
    <div id="tool_box">
        <div class="wrap">
            <div class="tool">
                <ul class="tool_ul">
                    <li class="tool_li">当前实际抢购信息</li>
                    <li class="tool_li">
                        <p class="tool_p1"><span class="tool_sp1">实际在线人数:</span><span class="tool_line">{{$actual_online_num}}</span></p>
                        <p class="tool_p2"><span class="tool_sp2">实际订单数:</span><span class="tool_order">{{$order_num}}</span></p>
                    </li>
                    <li class="tool_li">
                        <p class="tool_p1"><span class="tool_sp1">已付款订单数:</span><span class="tool_old">{{$pay_num}}</span></p>
                        <p class="tool_p2"><span class="tool_sp2">已付金额数:</span><span class="tool_money">
                                @if(empty($total_price))
                                    0
                                @else
                                    {{$total_price}}
                                @endif
                            </span></p>
                    </li>
                    <li class="tool_li">当前虚拟抢购信息</li>
                    <li class="tool_li">
                        <p class="tool_p3"><span class="tool_sp3">虚拟人数:</span><span class="tool_people">{{count($fake_user_come)}}</span></p>
                        <p class="tool_p4"><span class="tool_sp4">虚拟购买/<b>手</b>:</span><span class="tool_buy">{{$fake_user_buy}}</span></p>
                    </li>
                    <li class="tool_li">
                        <p class="tool_p5">
                            <span class="tool_sp3">删除人数:</span>
                            <input id="remove_num" class="tool_inp" maxlength="6" type="text" placeholder="输入要删除的在线人数" />
                        </p>
                        <a class="tool_a" href="javascript:;" onclick="deleteImg()">确定</a>
                    </li>
                    @if($product->start_at)
                    <li class="tool_li">添加抢购时间</li>
                        <li class="store_data">
                            <input type="hidden" name="param" class="param" />
                           <div class="data_start"> {{ $product->start_at }}</div>
                            <span class="store_across">-</span>
                            @if($product->end_at == 0)
                            <input type="text"  readonly placeholder="抢购结束时间" data-role="datebox" class="data_end data" id="appDateTime2" />
                            @else
                                <input type="text" value="{{ $product->end_at }}"  readonly placeholder="抢购结束时间" data-role="datebox" class="data_end data" id="appDateTime2" />
                            @endif
                        </li>
                    @endif
                </ul>
                <div class="tool_btn"><a class="btn btn-info" href="/merchantTool?good_id={{$good_id}}&user_id={{$product->merchant_id}}">添加虚拟抢购信息</a></div>
            </div>
        </div>
        <div class="tool_hide" style="display:none;">
            <p class="tool_pass"></p>
            <p class="tool_ok">确定</p>
        </div>
        <div class="tool_mask" style="display:none;"></div>
    </div>
</body>
</html>
<script>
    var date_id='{{$good_id}}';
    var t= localStorage.getItem(date_id);
    if(t==""){
        $(".data_end").val("");
    }else{
        $(".data_end").val(t);
    }
    $(".data_end").on('focus',function(){
        var good_id ='{{$good_id}}';
        $('.store_across').attr("id",good_id);
    });
    $(document).on('click','.dwb-n',function(){
        var id= $('.store_across').attr("id");
        $("#"+id).next(".data_end").val("");
        var date_id='{{$good_id}}';
        localStorage.setItem(date_id,"");
        $.ajax({
            url: '/Business/setProductEndTime',
            type: 'post',
            data: {'end_at': 0,'pro_id': date_id},
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            dataType: "json",
            success: function (data) {
                //console.log(data);
            }
        })
    });
    $(function() {
        var currYear = (new Date()).getFullYear();
        var good_id ='{{$good_id}}';
        var str=$(".data_start").text();
        var start = new Date(str).getTime();
        var now=new Date().getTime();
        if(start>now){//开始时间大于当前时间，开始时间推迟4天，还未开始抢购
            var val = str.split(" ");
            var validity = val[1].split("/");
            var year=validity[0];
            var month=validity[1] - 1;
            var day=validity[2];
            var min = val[2].split(":");
            var hour=min[0];
            var minute=min[1];
        }else{//开始时间小于当前时间，当前时间推迟4天，已经开始抢购了
            var now1 = new Date();
            var year = now1.getFullYear();
            var month = now1.getMonth();
            var day = now1.getDate();
            var hour = now1.getHours();
            var minute = now1.getMinutes();
        }
        var opt = {};
        opt.datetime = {preset:'datetime',stepMinute:1};
        opt.default = {
            theme: 'android-ics light', //皮肤样式
            display: 'bottom', //显示方式
            mode: 'scroller', //日期选择模式
            lang: 'zh',
            startYear: currYear, //开始年份currYear - 10,
            endYear: currYear + 1,//结束年份currYear + 10
            minDate: new Date(year,+month,+day,+hour ,+minute+5),
            maxDate: new Date(year,+month,+day+4,+hour,+minute ),
            setText: '确定',
            cancelText: '取消',
            /*清楚默认样式，更改中文模式*/
            dateFormat: 'yyyy/mm/dd',
            dateOrder: 'yymmdd',
            dayNames: ['周日', '周一;', '周二;', '周三', '周四', '周五', '周六'],
            dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
            dayText: '日',
            hourText: '时',
            minuteText: '分',
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            monthText: '月',
            secText: '秒',
            timeFormat: 'HH:ii',
            timeWheels: 'HHii',
            yearText: '年',
            onSelect:function(valueText,inst){
                if(valueText !=''){
                    var end_at=valueText;
                    var pro_id='{{$good_id}}';
                    setTimeout(function(){
                        $(".tool_pass").html('结束时间设置成功');
                        $(".tool_hide").show();
                        $(".tool_mask").show();
                        $.ajax({
                            url: '/Business/setProductEndTime',
                            type: 'post',
                            data: {'end_at': end_at,'pro_id': pro_id},
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            dataType: "json",
                            success: function (data) {
                                //console.log(data);
                            }
                        })
                    },300)
                }
                $(".tool_ok").click(function(){
                    window.location.href="/Business/producListRel";
                })
                var v=valueText;
                var date_id='{{$good_id}}';
                localStorage.setItem(date_id,v);
            }
        };
        var optDateTime = $.extend(opt['datetime'], opt['default']);//年月日时分型
        $(".data_end").mobiscroll(optDateTime).datetime(optDateTime);
    });
    /*监听删除人数*/
    $(document).on('input','.tool_inp',function () {
        var value = $('.tool_inp').val();
        var reg=/^[0-9]*$/;
        if(reg.test(value)==true){

        }else{
            $(".tool_pass").html('请输入有效的数字！');
            $(".tool_hide").show();
            $(".tool_mask").show();
            $('.tool_inp').attr("readonly",true);
            //$('.tool_inp').blur();
        }
    })
    /*点击遮罩层隐藏*/
    $(".tool_ok").click(function(){
        $(".tool_hide").hide();
        $(".tool_mask").hide();
        $('.tool_inp').val('');
        $('.tool_inp').attr("readonly",false);
        //$('.tool_inp').focus();
    })
    function deleteImg() {
        var remove_num = $('#remove_num').val();
        var good_id ='{{$good_id}}';
        var value = $('.tool_inp').val();
        if(value>'{{count($fake_user_come)}}'){
            $(".tool_pass").html('要删除人数大于虚拟人数！');
            $(".tool_hide").show();
            $(".tool_mask").show();
        }else {
            $.ajax({
                url: '/merchantTool/deleteImg',
                type: 'get',
                data: {
                    'remove_num': remove_num,
                    'good_id': good_id
                },
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.msg.length > 9) {
                        $(".tool_pass").text(data.msg);
                        $(".tool_hide").show();
                        $(".tool_mask").show();
                        $(".tool_ok").click(function () {
                            location.reload();
                        })
                    }
                }
            })
        }
    }
</script>